package com.ieslab.powergrid.demosvr.service;

import com.ieslab.powergrid.demosvr.entity.Person;
import com.ieslab.powergrid.demosvr.entity.TestEvent;
import lombok.extern.slf4j.Slf4j;
import org.springframework.context.ApplicationContext;
import org.springframework.stereotype.Service;

import javax.annotation.Resource;

//发布事件触发器
@Service
@Slf4j
public class TestService {
    @Resource
    private ApplicationContext applicationContext;

    /**
     * 发布事件
     * @return
     */
    public Person getPerson() {
        Person person = new Person("", "斌哥","","济南");
        // 发布事件
        TestEvent event = new TestEvent(this, person);
        applicationContext.publishEvent(event);
        log.info("触发器被触发");
        return person;
    }

}
